package com.wg.springboothandler.config;

import com.wg.springboothandler.Interceptor.UserInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Description:
 * @Author WuGang
 * @Date 2021/10/20 19:09
 * @Version 1.0
 */
@Configuration  //定义此类为配置文件  和之前的配置类的两个注解不一样
public class InterceptorConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//        要拦截的路径
        String[] addPathPatterns={
//                拦截user路径下面的所有路径
                "/user/**"
        };
//        要排除拦截的路径
        String[] excludePathPatterns={
                "/user/out","/user/error","/user/login"
        };
//        注册一个拦截器类
        registry.addInterceptor(new UserInterceptor()).addPathPatterns(addPathPatterns).excludePathPatterns(excludePathPatterns);
    }
}
